package com.kaiyiweitong.tongxing.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.kaiyiweitong.tongxing.R;
import com.kaiyiweitong.tongxing.bean.AfterSellResData;
import com.kaiyiweitong.tongxing.util.CommonUtil;

import java.util.List;

/**
 * Created by Administrator on 2017/12/18 0018.
 */

public class AfterSellItemAdapter extends RecyclerView.Adapter {
    private Context mContext;
    private final LayoutInflater mInflater;
    private List<AfterSellResData> mData;

    public AfterSellItemAdapter(Context context, List<AfterSellResData> data) {
        mContext = context;
        mInflater = LayoutInflater.from(context);
        mData = data;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.item_after_sell_item, null);
        MyViewHolder myViewHolder = new MyViewHolder(view);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        MyViewHolder viewHolder = (MyViewHolder) holder;
        AfterSellResData bean = mData.get(position);
        Glide.with(mContext).load(bean.getGoods_img()).into(viewHolder.pic);
        if (CommonUtil.isNotEmpty(bean.getGoods_name())) {
            viewHolder.title.setText(bean.getGoods_name());
        }
        if (CommonUtil.isNotEmpty(bean.getGoods_intro())) {
            viewHolder.content.setText(bean.getGoods_intro());
        }
    }

    @Override
    public int getItemCount() {
        if (mData != null && mData.size() > 0) {
            return mData.size();
        } else {
            return 0;
        }
    }

    private class MyViewHolder extends RecyclerView.ViewHolder {
        private ImageView pic;
        private TextView title;
        private TextView content;

        public MyViewHolder(View itemView) {
            super(itemView);
            pic = itemView.findViewById(R.id.pic);
            title = itemView.findViewById(R.id.title);
            content = itemView.findViewById(R.id.content);
        }
    }
}
